function r2 = calc_r2(s)
h_avg = mean(mean(s.h));
h_dev = s.h - h_avg;
r2 = sum(sum(h_dev.^2))/(length(s.x)*length(s.y));